package com.atguigu.kmp;

/**
 * @author RuiKnag
 * @create 2021-05-31-14:26
 */
public class ViolenceDemo {
    public static void main(String[] args) {
        String str1="硅硅谷 尚硅谷你尚谷 尚硅谷你尚硅谷你尚硅你好";
        String str2="尚硅谷你尚硅你好";
        int i = pipei(str1, str2);
        System.out.println(i);
    }
    public static int pipei(String str1,String str2){
        char[] c1 = str1.toCharArray();
        char[] c2 = str2.toCharArray();

        for (int i = 0; i < str1.length(); ) {
            int k=i;
            for (int j = 0; j < str2.length(); j++) {
                if(c1[k++]!=c2[j]){
                    i++;
                    break;
                }
                if(j==str2.length()-1){
                    return i;
                }
            }
        }
        return -1;
    }
}
